/*
 * File      : application.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2009-01-05     Bernard      the first version
 * 2014-04-27     Bernard      make code cleanup.
 */

#include <board.h>
#include <rtthread.h>
#include <drivers/pin.h>

extern void rt_platform_init(void);

/**
 * @desc  : 挂载文件系统
 * @param : none
 * @return: none
 */
int rt_dfs_mount_init(void)
{
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
    /* mount spi flash fat partition as root directory */
    if (dfs_mount("flash0", "/", "elm", 0, 0) == 0)
    {
        mkdir("/sd0", 0);   //create 2ed partition mount point
        rt_kprintf("File System initialized!\n");
    }
    else
    {
        rt_kprintf("File System initialzation failed!\n");
    }
#ifdef RT_USING_SDCARD
    /* mount sd card fat partition as /sd0 directory */
    if (dfs_mount("sd0", "/sd0", "elm", 0, 0) == 0)
    {
        rt_kprintf("File System initialized!\n");
    }
    else
    {
        rt_kprintf("File System initialzation failed!\n");
    }
#endif /* RT_USING_SDCARD */
#endif /* RT_USING_DFS && RT_USING_DFS_ELMFAT */
}
INIT_ENV_EXPORT(rt_dfs_mount_init);

/**
 * @desc  : 初始化任务 创建任务 执行一些需要在其他任务启动之前执行的命令
 * @param : parameter
 * @return: none
 */
void rt_init_thread_entry(void *parameter)
{
    rt_platform_init();

    //bsp以上级别的组件初始化
    rt_components_init();

    get_boot_time_write_bootlog();
}

/**
 * @desc  : 该函数会在启动流程中调用 用于创建第一个任务
 * @param : none
 * @return: none
 */
int rt_application_init()
{
    rt_thread_t tid;

    tid = rt_thread_create("init",
                           rt_init_thread_entry, RT_NULL,
                           2048, RT_THREAD_PRIORITY_MAX / 3, 20);
    if (tid != RT_NULL) rt_thread_startup(tid);

    return 0;
}

/*@}*/
